unit untConsultaPadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ActnList, cxPropertiesStore, cxContainer, cxEdit,
  cxClasses, cxStyles, cxGridTableView, cxLookAndFeels,
  cxGridCustomPopupMenu, cxGridPopupMenu, ImgList, cxGraphics, DB,
  IBCustomDataSet, dxBarDBNav, dxBar, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxDBData, cxGridLevel, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridDBTableView, cxGrid, cxPC, dxmdaset,
  ACBrBase, ACBrEnterTab, cxIntlBase, cxintl,cxStorage,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, dxSkinsdxBarPainter;

type
  TfrmConsultaPadrao = class(TForm)
    cxImageList1: TcxImageList;
    GridPopupMenu: TcxGridPopupMenu;
    StyleRepository: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle3: TcxStyle;
    cxStyle4: TcxStyle;
    cxStyle5: TcxStyle;
    cxStyle6: TcxStyle;
    cxStyle7: TcxStyle;
    cxStyle8: TcxStyle;
    cxStyle9: TcxStyle;
    cxStyle10: TcxStyle;
    cxStyle11: TcxStyle;
    cxStyle12: TcxStyle;
    cxStyle13: TcxStyle;
    cxStyle14: TcxStyle;
    GridTableViewStyleSheetDevExpress: TcxGridTableViewStyleSheet;
    cxEditStyleController1: TcxEditStyleController;
    cxPropertiesStore: TcxPropertiesStore;
    ActionList1: TActionList;
    ActNext: TAction;
    ActLast: TAction;
    ActFilter: TAction;
    ActFechar: TAction;
    ActExportar: TAction;
    dtEdit: TIBDataSet;
    dsRegistro: TDataSource;
    dxBarManager: TdxBarManager;
    dxBarManager1Bar1: TdxBar;
    btnCancelar: TdxBarButton;
    dxBarDBNavFirst1: TdxBarDBNavButton;
    dxBarDBNavPrior1: TdxBarDBNavButton;
    dxBarDBNavNext1: TdxBarDBNavButton;
    dxBarDBNavLast1: TdxBarDBNavButton;
    btnexportar: TdxBarButton;
    btnImprimir: TdxBarButton;
    dxBarDBNavigator1: TdxBarDBNavigator;
    pgcCadastro: TcxPageControl;
    tbsLista: TcxTabSheet;
    Panel1: TPanel;
    tbsEdita: TcxTabSheet;
    Panel2: TPanel;
    frmTreePadrao: TPanel;
    ActPrior: TAction;
    ActFirst: TAction;
    btnFilter: TdxBarButton;
    mtbFiltro: TdxMemData;
    dsFiltro: TDataSource;
    ACBrEnterTab1: TACBrEnterTab;
    cxIntl1: TcxIntl;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmConsultaPadrao: TfrmConsultaPadrao;

implementation

{$R *.dfm}

procedure TfrmConsultaPadrao.FormCreate(Sender: TObject);
var
  FMyStream: TMemoryStream;
  DirUser, Diretorio : String;
begin
  cxPropertiesStore.StorageName := TfrmConsultaPadrao(Sender).Name;
  cxPropertiesStore.StorageType := stStream;
  FmyStream := TMemoryStream.Create;
  cxPropertiesStore.StorageStream := FMyStream;
  DirUser := GetEnvironmentVariable('USERPROFILE');
  // Later I load the Stream from database
  if FileExists(DirUser+'\'+cxPropertiesStore.StorageName) then
  begin
    FMyStream.LoadFromFile(DirUser+'\'+cxPropertiesStore.StorageName);
    FMyStream.Position := 0;
    cxPropertiesStore.RestoreFrom;
  end;

  dtEdit.Close;
  dtEdit.Open;
end;

procedure TfrmConsultaPadrao.FormClose(Sender: TObject;
  var Action: TCloseAction);
var
  Diretorio :string;
  DirUser : String;
begin
   DirUser := GetEnvironmentVariable('USERPROFILE');
          (cxPropertiesStore.StorageStream as TMemoryStream).Position := 0;
           cxPropertiesStore.StoreTo(true);
          (cxPropertiesStore.StorageStream as TMemoryStream).SaveToFile((DirUser+'\'+cxPropertiesStore.StorageName));


  mtbFiltro.Open;
end;

procedure TfrmConsultaPadrao.FormShow(Sender: TObject);
begin
  mtbFiltro.Open;
  mtbFiltro.Append;
end;

end.
